package com.xm9m.ibczy.dsp.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.xm9m.ibczy.dsp.R;
import com.xm9m.ibczy.dsp.beans.AndoIntoBean;

import java.util.List;

/**
 * Created by baichuan on 2016/11/28.
 */

public class ThreeImgView extends BaseView {

    private View view;

    private ImageView imga, imgb, imgc;
    private TextView title, message;

    public ThreeImgView(Context context) {
        super(context);
        initThisView(context, null, 0);
    }

    public ThreeImgView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initThisView(context, attrs, 0);
    }

    public ThreeImgView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initThisView(context, attrs, defStyleAttr);
    }

    @Override
    public void initThisView(Context context, AttributeSet attrs, int defStyleAttr) {
        view = LayoutInflater.from(context).inflate(R.layout.avia_img3, this, true);
        imga = (ImageView) findViewById(R.id.advier_item_image1);
        imgb = ((ImageView) findViewById(R.id.advier_item_image2));
        imgc = ((ImageView) findViewById(R.id.advier_item_image3));
        title = ((TextView) findViewById(R.id.advier_item_title));
        message = ((TextView) findViewById(R.id.advier_item_message));
    }

    @Override
    public void bindView() {

        AndoIntoBean.AdsBean adsBean = bean.getAds().get(0);
        if (adsBean == null)
            return;
        title.setText(adsBean.getTitle());
        message.setText(adsBean.getContent());
        List<String> image_urls = adsBean.getImage_urls();
        if (image_urls == null)
            return;

        if (1 <= image_urls.size()) {
            String s1 = image_urls.get(0);
            if (s1 != null)
                setImage(imga, s1);
        }
        if (2 <= image_urls.size()) {
            String s1 = image_urls.get(1);
            if (s1 != null)
                setImage(imgb, s1);
        }
        if (3 <= image_urls.size()) {
            String s1 = image_urls.get(2);
            if (s1 != null)
                setImage(imgc, s1);
        }

    }
}
